package com.ybwh.springboot1.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.ybwh.springboot1.jdbc.BaseDao;
import com.ybwh.springboot1.model.po.Dict;
import com.ybwh.springboot1.model.vo.DataTabelPageVo;

@Component
public class DictDao extends BaseDao {

	private static final String SELECT_RECORD_SQL = "select " + getEntityColumnSql(Dict.class) + "  from "
			+ getEntityTableName(Dict.class);
	private static final String SELECT_COUNT_SQL = "select count(*)  from " + getEntityTableName(Dict.class);

	public DataTabelPageVo<Dict> pageList(int start, int length, Map<String, Object> param) {
		List<Object> paramList = new ArrayList<>(3);
		StringBuilder whereSql = new StringBuilder(" where 1=1 ");
		if (null != param.get("dictGroup")) {
			whereSql.append(" and dict_group = ? ");
			paramList.add(param.get("dictGroup"));
		}

		if (null != param.get("isDel")) {
			whereSql.append(" and is_del = ? ");
			paramList.add(param.get("isDel"));
		}

		whereSql.append(" order by update_ts desc ");

		return queryDataTabelPageVo(start, length, SELECT_COUNT_SQL + whereSql.toString(),
				SELECT_RECORD_SQL + whereSql.toString(), Dict.class, paramList);
	}

	public List<Dict> queryByGroup(String dictGroup) {

		String sql = "select " + getEntityColumnSql(Dict.class) + "from" + getEntityTableName(Dict.class)
				+ " where dict_group=?";
		return query(sql, new Object[] { dictGroup }, Dict.class);
	}

}
